package com.nursing.controller.Elder;

import com.nursing.bean.CheckinCheckout;
import com.nursing.model.Result;
import com.nursing.service.CheckinCheckoutService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/elderCheckinCheckout")
public class ElderCheckinCheckoutController {

    private final CheckinCheckoutService checkinCheckoutService;

    public ElderCheckinCheckoutController(CheckinCheckoutService checkinCheckoutService) {
        this.checkinCheckoutService = checkinCheckoutService;
    }

    @PostMapping("/add")
    public Result<String> add(@RequestBody CheckinCheckout checkinCheckout) {
        checkinCheckoutService.insert(checkinCheckout);
        return Result.success("添加成功");
    }

    @DeleteMapping("/delete")
    public Result<String> delete(@RequestParam Integer id) {
        checkinCheckoutService.delete(id);
        return Result.success("删除成功");
    }

    @GetMapping("/getCheckinCheckoutById")
    public Result<List<CheckinCheckout>> getCheckinCheckoutById(@RequestParam Integer elderId) {
        return Result.success(checkinCheckoutService.getByElderId(elderId));
    }
}
